#include "StdAfx.h"
#include "LParam.h"

#include "lConfigFile.h"
//extern LParam * gparam = NULL;
//static LConfigFile * mconfigfile = NULL;

LParam::LParam(void)
{
	lsetClassname("lparam");
	mconfigfile = NULL;

	create();
}


LParam::~LParam(void)
{
	ldestory();
}
int LParam::create(  )
{
	mconfigfile = new LConfigFile(); //TRACE(_T("->LParam::create: 0x%x\n"), mconfigfile);	
	laddCreate(mconfigfile);
	gptAddress(mconfigfile, TEXT("LParam::create.mconfigfile"), sizeof(LConfigFile));

	return 0;
}
//void LParam::destory()
//{
//	if( mconfigfile ) { delete mconfigfile; mconfigfile = NULL; }
//}
int LParam::init()
{

	//lautoInitobj( mconfigfile );
	//mconfigfile->linit();
	mconfigfile->setFilename(TEXT("lconfig.ini"));
	mconfigfile->updatePath();

	load();
	return 0;

}
void LParam::exit()
{
	save();
	//mconfigfile->lexit();
}
int LParam::load()
{
	TRACE(_T("-> lparam.load: enter\n" ));

	if ( !mconfigfile->isEixst())
	{
		TRACE(_T("-> lprm.load: lconfigfile is not exist;\n"));
		return -1;
	}

	int d;
	CString s;

	CString sec = TEXT("lcom");

	mtest = mconfigfile->GetInt(sec, TEXT("test"), -1 );
	TRACE(TEXT("-> lparam.load: test=%d\n"), mtest );

	//s = cf->GetStr(sec,(CString)TEXT("dir"));	
	//d = cf->GetInt(sec,TEXT("islog"),0);		gIslog			= d;
	//d = cf->GetInt(sec,TEXT("clock"),-1);		mpftt->setClockMode(d);

	return 0;
}
int LParam::save()
{
	int ret = 0;

	if ( !mconfigfile->isEixst())
	{
		//if(  create( ) <0 )	return --ret;
		if (mconfigfile->createFile() < 0)
		{
			TRACE(_T("-> lparam.create: configfile create error;\n"));
			return --ret;
		}
		else
		{
			mconfigfile->setInt(TEXT("lcom"), TEXT("test"), ++mtest);
		}
	}

	return ret;
}

int LParam::sync( bool bload )
{
	if ( bload )
	{
		return load();
	}
	else
	{
		return save();
	}
}